/**
 * Created by evan on 2017/9/26.
 */
var doubleValidation={
    curPage:1,
    pageSize:10,
    dataCache:null,
    init:function () {
        doubleValidation.setPageChange(null);
        doubleValidation.search();
    },
    setPageChange:function (delCurPage) {
        var url = 'mgr/safetyCtrl/getSafteList';
        var params ={   "actUserId":userId,
                        "curPage":doubleValidation.curPage,
                        "pageSize":99999};

        var cb = function(data) {
            if (data.size > 0) {
                var totalCount = data.size;
                var pageTotal = (totalCount / doubleValidation.pageSize > 0) ? Math.ceil(totalCount/ doubleValidation.pageSize) : 1;
                pageHelper.init(pageTotal,totalCount,doubleValidation.search,delCurPage);  //翻页事件
            }
        };
        sendApiNoLoad(url, params, cb, 'POST');
    },
    search:function (pageIdx) {
        var url = 'mgr/safetyCtrl/getSafteList';
        if (typeof(pageIdx) != "undefined"){
            doubleValidation.curPage=pageIdx;
        }
        var params ={   "actUserId":userId,
            "curPage":doubleValidation.curPage,
            "pageSize":$('#pageSize').val()};

        var cb = function(data) {
            if (data.resultCode == 200) {
                $('#tableList tbody').empty();
                var tr='';
                if(data.result!=null&&data.result.length>0){
                    for(var i=0;i<data.result.length;i++){
                        var singleObj=data.result[i];
                        localStorage.setItem(singleObj.id + "_Double_Validation", JSON.stringify(singleObj));
                        tr += '<tr class="row" ><td class="col-md-1">'
                            + '<input type="checkbox" name ="checkItem" style="margin-right: 10px;" value="' + singleObj.id + '"  class="checkItem"/>'
                            + '<input type="hidden" name="id" value="'+singleObj.id+'"/>'
                            + (i+1)
                            + '</td><td class="col-md-1">'
                            + singleObj.field01
                            + '</td><td class="col-md-2">'
                            + singleObj.field03
                            + '</td><td class="col-md-1">'
                            + singleObj.field02
                            + '</td><td class="col-md-2">'
                            + singleObj.field04
                            + '</td><td class="col-md-2">'
                            + (singleObj.keyName=="SAFETY_PAY_BACK" ? "回款划拔":"销户")
                            + '</td><td class="col-md-2">'
                            + singleObj.safetyDesc
                            + '</td><td class="col-md-2">'
                            +'<a type="button" name="sysUser_254" class="btn btn-default btn-xs updateData" style="margin-left: 5px; margin-top: 10px; display:none;">'
                            +'<i class="fa fa-minus-square-o"></i>修改</a>'
                            +'</td></tr>';
                    }
                    $('#tableList tbody').html(tr);
                    jsUtils.controlFunctionBtn();
                    doubleValidation.bindEventOtherBtn();
                }

            }else{
                alert(data.msg);
                tr='<tr><td colspan="9" style="text-align: center;color: red;">暂无数据</td></tr>';
                $('#tableList tbody').html(tr);
            }
        };
        sendApiNoLoad(url, params, cb, 'POST');
    },
    bindEventOtherBtn:function () {
        $(".updateData").on("click",function () {
            var thisObj=$(this);
            var id=thisObj.parent().parent().find('input[name="id"]').eq(0).val();
            art.dialog.data('doubleValidationId', id);
            var returnStatus = false;
            var path=APP_ADDRESS+'mgr/safety/doubleValidation/doubleValidationUpdate.jsp';
           var dialog= art.dialog.open(path, {
                title: '修改',
                width: 450,
                height:250,
                ok: function () {
                    returnStatus = this.iframe.contentWindow.submitForm();
                    if(returnStatus){
                        dialog.close();
                        doubleValidation.setPageChange(null);
                        doubleValidation.search();
                    }
                    return false;
                },
                cancel: true
            });

        })
    }

};

$(document).ready(function() {
    doubleValidation.init();
});
//提供给外部刷新调用
function refashData(){
    doubleValidation.setPageChange(null);
}